import { fileURLToPath } from 'url'

import { defineConfig, mergeConfig, loadEnv } from 'vite'

import baseConfig from '../../vite.config.js'

// 获取环境变量
const config = loadEnv('development', './')

// https://vite.dev/config/
export default defineConfig(() => {
  return mergeConfig(baseConfig, {
    base: process.env.NODE_ENV === 'development' ? '/' : '/admin-system/',
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      port: 5003,
      proxy: {
        '/dev': {
          target: config.VITE_APP_SERVICE_URL, // 开发
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev/, '')
        }
      }
    }
  })
})
